package com.godyao.framework.aop.aspectj;

import com.godyao.framework.aop.Pointcut;
import com.godyao.framework.aop.PointcutAdvisor;
import org.aopalliance.aop.Advice;

import java.util.Optional;

/**
 * @author godyao
 */
public class AspectJExpressionPointcutAdvisor implements PointcutAdvisor {
    /**
     * 切面
     */
    private AspectJExpressionPointcut pointcut;


    /**
     * 增强 具体的拦截方法
     */
    private Advice advice;

    /**
     * 拦截表达式
     */
    private String expression;

    @Override
    public Advice getAdvice() {
        return advice;
    }

    @Override
    public Pointcut getPointcut() {
        return Optional.ofNullable(pointcut).orElse(new AspectJExpressionPointcut(expression));
    }

    public void setAdvice(Advice advice) {
        this.advice = advice;
    }

    public void setExpression(String expression) {
        this.expression = expression;
    }
}
